<template>
	<view class="logincard">
		<view class="loginbox">
			<u-row customStyle="margin-bottom: 10px">
				<u-col span="3">
					<view class="title"  style="display: flex;
					align-items: center;">手机号</view>
				</u-col>
				<u-col span="9">
					<u--input placeholder="请输入内容" border="surround" v-model="phonevalue"
						@change="phonechange"></u--input>
				</u-col>
			</u-row>
			<u-row customStyle="margin-bottom: 10px">
				<u-col span="3">
					<view class="title" style="display: flex;
					align-items: center;">验证码</view>
				</u-col>
				<u-col span="9">
					<view class="u-demo-block__content" style="margin-top: 15px;">
						<!-- 注意：由于兼容性差异，如果需要使用前后插槽，nvue下需使用u--input，非nvue下需使用u-input -->
						<!-- #ifndef APP-NVUE -->
						<u-input placeholder="后置插槽">
						<!-- #endif -->
							<!-- #ifdef APP-NVUE -->
							<u--input placeholder="后置插槽">
							<!-- #endif -->
								<template slot="suffix">
									<u-code ref="uCode" @change="codeChange" seconds="20" changeText="X秒重新获取"></u-code>
									<u-button @tap="getCode" :text="tips" type="success" size="mini"></u-button>
								</template>
						<!-- #ifndef APP-NVUE -->
						</u-input>
						<!-- #endif -->
						<!-- #ifdef APP-NVUE -->
						</u--input>
						<!-- #endif -->
					</view>
				</u-col>
			</u-row>
			
			<view class="login" @click="loginfun">
				登录
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tips: '',
				value: '',
				phonevalue: ''
			}
		},
		watch: {
			value(newValue, oldValue) {
				// console.log('v-model', newValue);
			}
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			change(e) {
				console.log('change', e);
			},
			phonechange(e) {
				console.log('change', e);
			},
			loginfun(){
				var that = this
				      wx.getUserProfile({
				        desc:'用户信息授权',
				        success:(res)=>{
				            // that.data.userInfo = res.userInfo;
				            console.log(res.userInfo)
							wx.switchTab({
								url:'/pages/index/index'
							})
				        },
				        fail:(res)=>{
				          // debugger
				          console.log(res)
				        }
				      })
			
			}
		}
	}
</script>

<style lang="less">
	.login{
		width: 86%;
		margin: 30px auto;
		background: #5ac725;
		height: 40px;
		font-size: 20px;
		color: #fff;
		text-align: center;
		line-height: 40px;
		border-radius: 20px;
	}
	.logincard {
		width: 100%;
		height: 100vh;
		position: relative;
	}
	.title{
		text-align: center;
		
	}

	.loginbox {
		width: 90%;
		margin: 0 auto;
		position: relative;
		top: 20%;
	}

	.wrap {
		padding: 12px;
	}

	.demo-layout {
		height: 25px;
		border-radius: 4px;
	}

	.bg-purple {
		background: #CED7E1;
	}

	.bg-purple-light {
		background: #e5e9f2;
	}

	.bg-purple-dark {
		background: #99a9bf;
	}
</style>